package q876_middleNode;

import CommonClass.Common.ListNode;

public class Solution {
    /*
    快慢指针
    要求返回中点，若为偶数链表 则为中间后一个节点
     */
    public ListNode middleNode(ListNode head) {
        if (head.next == null) {
            return head;
        }

        ListNode slow = head, fast = head;
        while (fast.next != null && fast.next.next != null) {
            slow = slow.next;
            fast = fast.next.next;
        }

        return fast.next == null ? slow : slow.next;

    }
}
